<? include 'server_config.php'; 


if($_POST['new_drug_name']=="" || $user_idx=="")
{
	
	?>
	<script>
		alert("!");
	</script>
	<?
	return;
}

?>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<?



$sql = "

SELECT list_drug_idx FROM ndd_list_drug WHERE ProductNameKr='$new_drug_name';
";

//echo $sql;
$result = mysql_query($sql,$connect);

$row = mysql_fetch_row($result);

if($row[0]=="")
{

	$sql = "

	INSERT INTO ndd_list_drug (ProductNameKr) VALUES 
	( '$new_drug_name' );
	";

	//echo $sql;
	$result = mysql_query($sql,$connect);

	$sql = "

	SELECT list_drug_idx FROM ndd_list_drug WHERE ProductNameKr='$new_drug_name';
	";

	//echo $sql;
	$result = mysql_query($sql,$connect);

	$row = mysql_fetch_row($result);
	
}




$list_drug_idx = $row[0];


$sql = "

INSERT INTO ndd_drug (user_idx, list_drug_idx, disease_idx, reg_timestamp,

dosage_count, dosage_period, dosage_period_type, start_date, dosage_fq, drug_type
) VALUES 
( $user_idx, '$list_drug_idx', '$disease_idx', CURRENT_TIMESTAMP, 

'$new_dosage_count',
'$new_dosage_period', 
'$new_dosage_period_type', 
'$new_start_date', 
'$new_dosage_fq',
'$category_idx'


);
";

//echo $sql;
$result = mysql_query($sql,$connect);



$sql = "


INSERT INTO  `ndd_cure` (
`user_idx` ,
`disease_idx` ,
`description` ,
`description_type` ,
`reg_timestamp`
)
VALUES (
 '$user_idx',  '0',  '".$new_drug_name."(을)를 처방받았습니다.',  '10', 
CURRENT_TIMESTAMP
);
";

$result = mysql_query($sql,$connect);

?>

<script> 
parent.load_drug_list(0);
</script>











